package br.usp.ime.protoc.genotipagem;

import java.util.HashSet;
import java.util.Iterator;

import br.usp.ime.protoc.fujaba.FEmptyIterator;

public class AmostraSangue
extends Amostra
{
   /**
    * <pre>
    *                1         has          1..* 
    * AmostraSangue ----------------------------- TuboSoro
    *                amostraSangue      tuboSoro 
    * </pre>
    */
   private HashSet tuboSoro;

   public boolean addToTuboSoro(TuboSoro value)
   {
      boolean changed = false;
      if (value != null)
      {
         if (this.tuboSoro == null)
         {
            this.tuboSoro = new HashSet (); // or FTreeSet () or FLinkedList ()
         }
         
         changed = this.tuboSoro.add (value);
         if (changed)
         {
            value.setAmostraSangue (this);
         }
         
      }
      return changed;
   }

   public boolean hasInTuboSoro(TuboSoro value)
   {
      return ((this.tuboSoro != null) &&
              (value != null) &&
              this.tuboSoro.contains (value));
   }

   public Iterator iteratorOfTuboSoro()
   {
      return ((this.tuboSoro == null)
              ? FEmptyIterator.get ()
              : this.tuboSoro.iterator ());
   }

   public void removeAllFromTuboSoro()
   {
      TuboSoro tmpValue;
      Iterator iter = this.iteratorOfTuboSoro ();
      while (iter.hasNext ())
      {
         tmpValue = (TuboSoro) iter.next ();
         this.removeFromTuboSoro (tmpValue);
      }
   }

   public boolean removeFromTuboSoro(TuboSoro value)
   {
      boolean changed = false;
      if ((this.tuboSoro != null) && (value != null))
      {
         
         changed = this.tuboSoro.remove (value);
         if (changed)
         {
            value.setAmostraSangue (null);
         }
         
      }
      return changed;
   }

   public int sizeOfTuboSoro()
   {
      return ((this.tuboSoro == null)
              ? 0
              : this.tuboSoro.size ());
   }

   public void removeYou()
   {
      removeAllFromTuboSoro ();
      super.removeYou ();
   }

}
